<?php include _include(APP_PATH.'view/htm/header_thread.inc.htm');?>

<!--{hook user_create_start.htm}-->

<div class="ModalManager modal fade in show d-block">
    <div class="Modal modal-dialog Modal--small SignUpModal">
        <div class="Modal-content" style="margin-top: -52px">
            <div class="Modal-close App-backControl">
                <button class="Button Button--icon Button--link hasIcon win-back" type="button">
                    <i class="icon fa fa-times Button-icon"></i>
                </button>
            </div>
            <form action="<?php echo url('user-create');?>" method="post" id="form">
                <div class="Modal-header">
                    <h3 class="App-titleControl App-titleControl--text"><?php echo lang('user_create');?></h3>
                    <!--{hook user_create_title_after.htm}-->
                </div>
                <div class="Modal-alert"></div>
                <div class="Modal-body">
                    <div class="LogInButtons">

                    </div>
                    <div class="Form Form--centered">
                        <div class="Form-group">
                            <input class="FormControl" type="text" placeholder="<?php echo lang('username');?>" name="username" id="username">
                        </div>
                        <!--{hook user_create_email_after.htm}-->

                        <div class="Form-group">
                            <input class="FormControl" type="email" placeholder="<?php echo lang('email');?>" name="email" id="email" required>
                        </div>
                        <!--{hook user_create_username_after.htm}-->

                        <div class="Form-group">
                            <input class="FormControl" type="password" placeholder="<?php echo lang('password');?>" name="password" id="password">
                        </div>
                        <!--{hook user_create_password_after.htm}-->

                        <div class="Form-group">
                            <button class="Button Button--primary Button--block" type="submit" id="submit" data-loading-text="<?php echo lang('submiting');?>..." <?php if($conf['user_create_email_on']) { ?>disabled<?php } ?>>
                                <span class="Button-label"><?php echo lang('next_step');?></span>
                            </button>
                        </div>
                        <!--{hook user_create_submit_after.htm}-->

                    </div>
                </div>
                <div class="Modal-footer">
                    <p class="SignUpModal-logIn">已经注册过了？<a href="<?php echo url('user-login');?>">登录</a></p>
                </div>
            </form>
        </div>
    </div>
</div>

<!--{hook user_create_end.htm}-->

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>

<script src="<?php echo $conf['view_url'];?>js/md5.js"></script>

<script>
var jform = $('#form');
var jsubmit = $('#submit');
var jsend = $('#sendcode');
var referer = '<?php echo http_referer();?>';
jsend.on('click', function() {
    jform.reset();
    jsend.button('loading');
    var postdata = jform.serialize();
    $.xpost(jsend.attr('action'), postdata, function(code, message) {
        if(code == 0) {
            $('#code').focus();
            var t = 60; // 倒计时
            jsend.button('<?php echo lang('user_send_sucessfully');?> 60 ');
            jsubmit.button('reset');
            // 倒计时，重新发送
            var handler = setInterval(function() {
                jsend.button('<?php echo lang('user_send_sucessfully');?> '+(--t)+' ');
                if(t == 0) {
                    clearInterval(handler);
                    jsend.button('reset');
                }
            }, 1000);
        } else if(code < 0) {
            $.alert(message, -1);
            jsend.button('reset');
        } else {
            jform.find('[name="'+code+'"]').alert(message).focus();
            jsend.button('reset');
        }
    });
    return false;
});

jform.on('submit', function() {
    var postdata = jform.serializeObject();
    jsubmit.button('loading');
    postdata.password = $.md5(postdata.password);
    $.xpost(jform.attr('action'), postdata, function(code, message) {
        if(code == 0) {
            jsubmit.button(message).delay(1000).location(referer);
        } else if(xn.is_number(code)) {
            alert(message);
            jsubmit.button('reset');
        } else {
            jform.find('[name="'+code+'"]').alert(message).focus();
            jsubmit.button('reset');
        }
    });
    return false;
});

</script>

<!--{hook user_create_js.htm}-->